/*
 * 
 * @author		: Anand Sivadas
 * @version		: 0.1
 * @Date		: Jul 21, 2014
 * 
 */
package com.sivadas.anand.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.sivadas.anand.entity.EmployeeEntity;
import com.sivadas.anand.service.EmployeeService;

/**
 * The Class EmployeeController.
 *
 * @author 	: Anand Sivadas
 * @Date 	: Jul 21, 2014
 */
@Controller
public class EmployeeController {
	
	@Autowired
	private EmployeeService employeeService;
	
	/**
	 * List contacts.
	 *
	 * @param map the map
	 * @return the string
	 */
	@RequestMapping("/")
    public String listContacts(Map<String, Object> map) {
 
        map.put("employee", new EmployeeEntity());
        map.put("employeeList", employeeService.listEmployees());
 
        return "employee";
    }
 
    /**
     * Adds the contact.
     *
     * @param employee the employee
     * @param result the result
     * @return the string
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String addContact(@ModelAttribute("employee")
    EmployeeEntity employee, BindingResult result) {
 
    	employeeService.addEmployee(employee);
 
        return "redirect:/";
    }
 
    /**
     * Delete contact.
     *
     * @param employeeId the employee id
     * @return the string
     */
    @RequestMapping("/delete/{employeeId}")
    public String deleteContact(@PathVariable("employeeId")
    Integer employeeId) {
 
    	employeeService.removeEmployee(employeeId);
 
        return "redirect:/";
    }
	
}
